package com.mit.common.exception;

/**
 * Supperclass of all checked exception. The presentation tier can generate
 * correspond message by the resouces and the bundle you provide. <br/> e.g.
 * BaseException("resources","error.fatal") <br/> The System will search
 * "error.fatal" in the resource file named "resources.properites", and present
 * the corresponding message to users. <br/> In case of
 * BaseException.setMessage() called, the error message will also be displayed
 * 
 * @author River Yu
 * 
 */
public class BaseException extends Exception {

	public static final String DEFAULT_RESOURCE =  "resources";
	public static final String DEFAULT_MSG = "error.common.fatalerror";
	protected String bundle = DEFAULT_MSG ;
	protected String resource = DEFAULT_RESOURCE;
	protected Object[] arguments;
	protected Throwable cause;

	
	public BaseException(){
		super();

	}
	
	public BaseException(String message){
		super(message);

	}
	
	public BaseException(Throwable t){
		super(t);
		cause = t;
		if(t instanceof BaseException){
			bundle = ((BaseException) t).getBundle();	
			arguments =  ((BaseException) t).getArguments();
		}
	}
	public BaseException(String msg, Throwable t){
		super(msg, t);
		if(t instanceof BaseException){
			bundle = ((BaseException) t).getBundle();	
			arguments =  ((BaseException) t).getArguments();
		}

	}
	
	public BaseException(String res, String bnd){
		super();
		bundle = bnd;
		resource = res;
	}
	public BaseException(String res, String bnd, Object[] args){
		super();
		bundle = bnd;
		resource = res;
		arguments = args;
	}
	
	public Throwable getCause(){
		return cause;
	}


	public void setBundle(String bundle) {
		this.bundle = bundle;
	}

	public void setResource(String resource) {
		this.resource = resource;
	}

	public void setArguments(Object[] arguments) {
		this.arguments = arguments;
	}

	public void setCause(Throwable cause) {
		this.cause = cause;
	}

	public String getBundle() {
		return bundle;
	}

	public String getResource() {
		return resource;
	}

	public Object[] getArguments() {
		return arguments;
	}
	
	
}
